/*
 * @Overview:   axios-error
 * @Author:     Zi_Jun
 * @Email:      zijun2030@163.com
 * @Date:       2020/12/9 11:22
 * @Mark:       //
 */
import { ElMessage } from 'element-plus';

/**
 * 展示错误提示
 * @param message {string} 错误描述
 */
export const showErrorMessage = (message: string): any => {
  return ElMessage({
    message,
    type: 'error',
  });
};

export const ERROR_CODE: Array<any> = [
  { code: 400, msg: '请求错误' },
  { code: 401, msg: '未授权，请登录' },
  { code: 403, msg: '拒绝访问' },
  { code: 404, msg: '请求地址出错' },
  { code: 408, msg: '请求超时' },
  { code: 500, msg: '服务器内部错误' },
  { code: 501, msg: '服务未实现' },
  { code: 502, msg: '网关错误' },
  { code: 503, msg: '服务不可用' },
  { code: 504, msg: '网络超时' },
  { code: 505, msg: 'HTTP版本不受支持' },
];

export function networkError(message: string) {
  let msg: string;
  if (message === 'Network Error') {
    msg = '网络错误';
  } else if (message.includes('timeout')) {
    msg = '网络超时';
  } else {
    msg = '未知错误';
  }
  showErrorMessage(msg);
}
